/*
 * Importer.java
 *
 * Created on September 11, 2007, 9:36 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.tools;

import java.io.File;
import java.net.URI;

/**
 *
 * @author alex
 */
public class Importer
{
   
   /**
    * @param args the command line arguments
    */
   public static void main(String[] args)
   {
      int argidx = 0;
      boolean exact = false;
      boolean excludeDot = false;
      String username = null;
      String password = null;
      while (argidx<args.length && args[argidx].charAt(0)=='-') {
         if (args[argidx].equals("--exact") || args[argidx].equals("-e")) {
            exact = true;
         } else if (args[argidx].equals("--exclude-dot-files")) {
            excludeDot = true;
         } else if (args[argidx].equals("--username") || args[argidx].equals("-u")) {
            argidx++;
            if (argidx==args.length) {
               System.err.println("The "+args[argidx-1]+" option requires a parameter.");
               System.exit(1);
            }
            username = args[argidx];
         } else if (args[argidx].equals("--password") || args[argidx].equals("-p")) {
            argidx++;
            if (argidx==args.length) {
               System.err.println("The "+args[argidx-1]+" option requires a parameter.");
               System.exit(1);
            }
            password = args[argidx];
         } else {
            System.err.println("Unknown option "+args[argidx]);
            System.exit(1);
         }
         argidx++;
      }
      
      if ((args.length-argidx)<2) {
         System.err.println("Usage: "+Importer.class.getName()+" {options} directory feed-uri");
         System.exit(1);
      }
      
      File dir = new File(args[argidx]);
      URI uri = URI.create(args[argidx+1]);
      
      DirectorySynchronizer importer = new DirectorySynchronizer(dir,uri);
      importer.setIdentity(username,password);
      importer.setExact(exact);
      importer.setExcludingDotFiles(excludeDot);
      
      try {
         importer.sync();
      } catch (Exception ex) {
         ex.printStackTrace();
      }
      
   }
   
}
